const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    picServer: 'http://appapp.b0.upaiyun.com',
    member: {},
  },
  onLoad: function (options) {
    this.initPage();
  },
  initPage:function(){
    wx.showLoading({
      title: '数据加载中....',
    })
    var _this=this;
    app.getUserInfoSyn({ "openId": wx.getStorageSync('openid') }).then(function (value) {
      wx.hideLoading();
      var userInfo = wx.getStorageSync('userInfo');
      _this.setData({
        member: userInfo.member
      })
    })
  },
  uploadImage:function(e){
    var datatype = e.currentTarget.dataset.type;
    var _this=this;
    var s="";
    if(datatype==0){
      s ="形象照上传成功~";
    }else if(datatype==3){
      s ="身份证上传成功~"
    }else if(datatype==4){
      s ="毕业证上传成功~"
    }
      wx.chooseImage({
        count: 1,
        success: function(res) {
          var tempFilePaths = res.tempFilePaths;//文件临时访问路径
          var tempFiles = res.tempFiles;//文件临时存储对象
          wx.uploadFile({
            url: app.globalData.SERVICE.USERCENTER.AVATARUPLOAD,
            filePath: tempFilePaths[0],
            name: 'imgFile',
            success: function (res) {
              if (typeof (res.data)=='string'){
               var  data = JSON.parse(res.data);
             }
            
              let url = data.url;
             app.doReq(app.globalData.SERVICE.USERCENTER.USERHEAD,{
               "id": app.globalData.userid,
               "type": datatype,
               "path": url
             },'get',function(res){
                  var data=res.data;
                  if(data.code==200){
                      wx.showToast({
                        title: s,
                        icon:'success',
                        duration:1000,
                      });
                      _this.initPage();
                  }
             });
            }
          })
        },
      })
  }
})